<template>
  <div class="container">
     <Tab  style="position:fixed; background-color:#fff; z-index:999"/>
    <van-cell title="申请人" :value="approver_num"/>
    <!-- 物料列表     -->
    <van-list>
      <div v-for="item in list" :key="item.id">
        <van-swipe-cell>
            <van-card
              :num="item.apply_num"
              :desc="item.product_type"
              :title="item.product_name"
            />
            <span class="type">{{item.wpg_name}}</span>
          </van-swipe-cell>
      </div>
    </van-list>
    <!-- 审核人 -->
    <van-cell is-link title="审核人" :value="reviewer" @click="show = true"/>
    <van-action-sheet v-model="show" :actions="actions" @select="onSelect"/>
    <!-- 选择时间
<van-datetime-picker
  v-model="currentDate"
  type="datetime"
  title="选择完整时间"
  :min-date="minDate"
  :max-date="maxDate"
  :confirm="confirm()"
    />-->

    <!-- 备注 -->
    <van-field
      v-model="message"
      rows="2"
      autosize
      label="备注"
      type="textarea"
      maxlength="50"
      placeholder="请输入备注"
      show-word-limit
    />
    <div style="height:80px"></div>
    <div class="footer">
      <van-button type="danger" round @click="cancel()">取消</van-button>
      <van-button type="primary" round @click="confirm()">确认</van-button>
    </div>
  </div>
</template>
<script>
import axios from "axios";
import { getCookie } from "Utils/cookie";
import { Toast } from "vant";
import Tab from 'Comp/Tab'
export default {
  data() {
    return {
      list: JSON.parse(this.$route.query.list),
      approver_num: getCookie("approver_num"),
      show: false,
      actions: [],
      reviewer: "",
      message: "",
      json: {},
      minDate: new Date(2020, 10, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: new Date(),
      id: ""
    };
  },
  components:{
    Tab,
  },
  methods: {
    onSelect(item) {
      // 默认情况下点击选项时不会自动收起
      // 可以通过 close-on-click-action 属性开启自动收起
      this.show = false;
      Toast(item.name);
      this.reviewer = item.name;
      this.id = item.approver_id;
      console.log(item)
    },
    cancel() {
      this.$router.back();
    },
    confirm() {
      console.log("list", this.list);

      if (this.reviewer == "") {//没选择审核人
        if (this.actions.length != 0) {//有审核人列表
          Toast.fail("请选择审核人");
          return;
        } else {//没有审核人列表
          axios({
            url: "/hrkc/Product/addBossApply",
            method: "POST",
            params: {
              approver_id: getCookie("approver_id"),
              remarks: this.message,
              org_code: getCookie("org_no"),
              approver_name: getCookie("approver_name"),
              apList: JSON.stringify(this.list)
            }
          })
            .then(res => {
              console.log(res);
              if (res.data.code == 0) {
                Toast.success(res.data.msg);
                this.$router.push("/application");
              }
            })
            .catch(error => Promise.reject(error));
        }
      }else{
          axios({
            url: "/hrkc/Product/addApply",
            method: "POST",
            params: {
              approver_id: getCookie("approver_id"),
              remarks: this.message,
              org_code: getCookie("org_no"),
              approver_name: getCookie("approver_name"),
              apList: JSON.stringify(this.list),
              nextapprover_id :this.id,
              nextapprover_name:this.reviewer,
            }
          })
            .then(res => {
              console.log('res',res);
              if (res.data.code == 0) {
                Toast.success(res.data.msg);
                this.$router.push("/application");
              }
            })
            .catch(error => Promise.reject(error));
        }
      }
    
  },
  mounted() {
    axios({
      url: "/hrkc/Approver/nextapproverList",
      method: "POST",
      params: {
        grade_tree: getCookie("grade_id"),
        org_code: getCookie("org_no")
      }
    })
      .then(res => {
        console.log(res);
        for (let i = 0; i < res.data.data.length; i++) {
          var json = {};
          // console.log("111111",res.data.data[i].product_name_value)
          json.name = res.data.data[i].approver_name;
          json.approver_id = res.data.data[i].id;
          this.actions.push(json);
        }
        console.log(this.actions);
      })
      .catch(error => Promise.reject(error));
  }
};
</script>
<style lang="scss" scoped>
// .van-list{
//     height:350px;
//     overflow: hidden;
// }
.van-card {
  height: 90px;
}
.van-card__content {
  height: 70px;
}
.van-card__title {
  height: 30px;
  line-height: 30px;
  font-size: 20px;
}
.van-card__desc {
  height: 20px;
  line-height: 20px;
  font-size: 15px;
}
.van-card__num {
  margin-top: -80px;
  font-size: 15px;
}
.van-card__footer {
  margin-top: -60px;
}
.type{
position: absolute;
top:60px;
left:10px
}
.footer {
  width: 100%;
  height: 80px;
  background-color: #fff;
  position: fixed;
  bottom: 0px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  .van-button {
    width: 150px;
  }
}
</style>